local UI = SecretaryUI

local function GetTableObject(this)
	return this:GetParent().object
end

local function Row_Layout(this)
	local parent = this:GetParent()
	local object = parent.object

	local columns = object:GetNumColumns()
	
	local height = object:GetRowHeight(this.row)
	local offset = - object:GetRowOffset(this.row)
	
	this:ClearAllPoints()
	this:SetPoint("TOPLEFT", parent, "TOPLEFT", 0, offset)
	this:SetPoint("TOPRIGHT", parent, "TOPRIGHT", 0, offset)
	this:SetHeight(height)
	
	local header = nil
	for col = 1, columns do
		local cell = this.cells[col]
		if not cell then
			cell = UI.MakeCell(this, this.row, col)
			this.cells[col] = cell
		end
		cell:ClearAllPoints()
		if header then
			cell:SetPoint("TOPLEFT", header.drag, "TOPLEFT", 0, offset)
		else
			cell:SetPoint("TOPLEFT", this, "TOPLEFT", 0, 0)
		end
		header = object:GetHeaderFrame(col)
		cell:SetPoint("TOPRIGHT", header.drag, "TOPLEFT", 0, offset)
		cell:SetHeight(height)
	end
end

local function MakeRow(parent, row)
	local frame = CreateFrame("Frame", parent:GetName().."Row"..row, parent)
	frame.row = row
	frame.cells = {}
	
	frame.Layout = Row_Layout
	
	frame:Layout()
	
	return frame
end

UI.MakeRow = MakeRow
